#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@Introduce :
@File      : opeartion_yaml.py
@Time      : 2022/7/4 18:54
@Author    : toby
"""


import  yaml

data={
    "user1":{
        "user":"admin",
        "passwd":"123456"
            },
    "user2":{
        "user":"13726412604",
        "passwd":"123456"
            }
    }


def write(file,data):
    # 打开
    stream = open(file,mode='a',encoding='utf-8')
    # 写入数据 ,allow_unicode  避免乱码
    yaml.dump(data,stream,allow_unicode=True)
    # 关闭工单
    stream.close()
    print("write over")


def read(filename):
    # 打开
    stream = open(filename,mode='r',encoding='utf-8')
    # 读取数据
    # 读取文件中的所有数据
    file_data = stream.read()
    stream.close()
    # 指定Loader
    data = yaml.load(file_data, Loader=yaml.FullLoader)
    return data

if __name__ == '__main__':
    filepath = "/root/flask-celery-hjw/flask-celery/user.yml"
    write(filepath,data)

    data = read(filepath)
    print(data)


